package org.mengyun.tcctransaction.sample.action;

import org.mengyun.tcctransaction.sample.domain.dto.OrderDto;
import org.mengyun.tcctransaction.sample.domain.dto.TransactionContextDto;
import org.mengyun.tcctransaction.sample.domain.service.IProductService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * xuejianxin
 */
@RequestMapping("")
@RestController("ProductController")
public class ProductController {

	@Autowired
	IProductService productService;

	// 事物上下文和参数一起传递
	@PostMapping(value = "/reduceStock")
	public String reduceStock(@RequestBody TransactionContextDto<OrderDto> tcd) {
		System.out.println("------------------------reduceStock");
		return productService.reduceStock(tcd.getContext(), tcd.getBody());
	}

}
